<?php


// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.model' );



class AplicacionModelAplicacion extends JModel
{
     
	var $_sitios =null;
	var $_pagination = null;
	var $_total = null;
	var $_limit = null;
	var $_limitstart = null;
	function __construct()
	{
		global $mainframe , $option;
		parent::__construct();
		$limit = JRequest::getVar('limit',$mainframe->getCfg('list_limit'));
		$limitstart = JRequest::getVar('limitstart', 0);
		$this->_limit = $limit;
		$this->_limitstart = $limitstart;
		$this->_total = $this->getTotal();
	}
	
   
     function getTotal(){
		if (empty($this->_total))
		{
			$query = $this->_buildObtenerSitios();
			$this->_total = $this->_getListCount($query);
		}
		return $this->_total; 
     }
    function _buildObtenerSitios(){
        $consulta = "select * from #__zsitio ";
    	return $consulta;
    }
    
    
    
    
    
    function introduceSitio($post,$pathFoto){
	    JTable::addIncludePath(JPATH_COMPONENT.DS.'tables'); //En Back-End no es necesario?!!
	    $file = JRequest::getVar( 'foto', null, 'files', 'array' );
	    $row =& JTable::getInstance('zsitio', 'Table');
	  	 if (!$row->bind($post)) {
	     	 //return JError::raiseWarning(500, $row->getError());
	     	 return 0;
	   	 }
	   	 if($pathFoto == null || $pathFoto = "")
	   	 {
	   	 	$row->foto = JURI::base().'components'.DS.'com_aplicacion'.DS.'fotos'.DS.'muestra.jpg';
	   	 }
	  	 if (!$row->store()) {
	      	return JError::raiseWarning(500, $row->getError());
	      	//return 0;
	  	 }
	  	return 1;		
    }
    
    /*function introduceSitio($titulo,$url,$foto,$video,$google_x,$google_y,$publicar,$categoria,$usuario,$tags)
    {
    	//fallo con el usuario y con la categoria
    	//validar los datos antes
    	//foto
    	//devolver un valor si se ha insertado o no, para llevar a vista de CORRECTO o FALLO
    	$query='call agregarSitio("'.$titulo.'","'.$url.'","'.$foto.'","'.$video.'",'.$google_x.','.$google_y.',"'.$publicar.'",'.$categoria.','.$usuario.',"'.$tags.'",",")';
    	$db=& JFactory::getDBO();
    	$db->Execute($query);
    	
    }*/
  

}
?>